#include <iostream>
#include <string>
#include <unistd.h>
#include <pthread.h>
#include <cerrno>
#include <sys/syscall.h>

using namespace std;

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

int cnt = 100;

void *startRoutine(void *args)
{
    while(true)
    {
        pthread_mutex_lock(&mutexA);
        sleep(1);
        pthread_mutex_lock(&mutexB);
    }
}

int main()
{
    pthread_t t1;
    pthread_create(&t1, nullptr, startRoutine, (void*)"thread 1");
    pthread_t t2;
    pthread_create(&t2, nullptr, startRoutine, (void*)"thread 2");

    pthread_join(t1, nullptr);
    pthread_join(t2, nullptr);

    return 0;
}